package search;

import java.util.ArrayList;
import query.Query;
import process.Result;
import util.JSONConverter;

public class Search {

	public static ArrayList<Result> doSearch(Query query) {
		String answer;
		Result result;
		ArrayList<Result> listaResult = new ArrayList<Result>();
		try {
			answer = Bing.search(query.getQueryString());
		} catch (Exception e) {
			System.out.println("busqueda fallida");
			return null;
		}
		ArrayList<ArrayList<String>> res = JSONConverter.parse(answer);
		if (res == null) return null;
		ArrayList<String> answ = res.get(0);
		ArrayList<String> docID = res.get(1);
		for(int i = 0; i<answ.size(); i++)
		{
			result = new Result(answ.get(i),query,docID.get(i));
			listaResult.add(result);
		}
		return listaResult;
	}
}
